home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS11.ADF / Forth / Breshenhan < prev    next >
Text File  |  1986-08-05  |  1KB  |  33 lines

  1. \ Bresenham's (or Mitchell's?) circle algorithm.
  2. \ I think it's published in "Fundamentals of Interactive Computer Graphics"
  3. \ by Foley and Van Dam.
  4. \ DOT uses XYSCALE, so the aspect ratio can be changed.
  5. \ I don't think there is much difference in speed between this and
  6. \ Multi-Forth's CIRCLE command, but they draw slightly different circles.
  7. \ I believe this draws a more symmetrical circle than Multi-Forth, and is
  8. \ a good example of the use of locals.  It would be a mess without them.
  9. \ There is room for optimization here, but I didn't want to fog things up.
  10. \ Jon R. Bryan 6-8-86
  11.  
  12. : CIRCLE   ( x center\y center\radius -- )
  13.    3 OVER 2* -  0
  14.    LOCALS|  x  d  y  ycenter xcenter  |
  15.    BEGIN   x y <
  16.    WHILE
  17.      xcenter y - 1+  ycenter x -     xcenter y +     OVER  DOT DOT
  18.      xcenter x -     ycenter y -     xcenter x + 1+  OVER  DOT DOT
  19.      xcenter y - 1+  ycenter x + 1+  xcenter y +     OVER  DOT DOT
  20.      xcenter x -     ycenter y + 1+  xcenter x + 1+  OVER  DOT DOT
  21.      d 0<
  22.      IF   x 4* 6+ ADDR.OF d +!
  23.      ELSE
  24.        x y - 4* 10+ ADDR.OF d +!
  25.        -1 ADDR.OF y +!
  26.      THEN
  27.      1 ADDR.OF x +!
  28.    REPEAT
  29.    x y =
  30.    IF   xcenter y - 1+  ycenter x -     xcenter y +     OVER  DOT DOT
  31.         xcenter x -     ycenter y + 1+  xcenter x + 1+  OVER  DOT DOT
  32.    THEN ;
  33.